﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Caching;
using KL.Store.Core.Domain;
using KL.Store.Core.Domain.Enum;
using TN.Data;

namespace KL.Store.Data
{
    public class dbWishLists
    {
        #region Get

        public static WishList Get(int UserId, long ListId)
        {
            IList<WishList> objectList = new List<WishList>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_WishList_Get", objectList, new object[] { UserId, ListId });

            return objectList.FirstOrDefault();
        }

        #endregion

        #region GetList

        public static IList<WishList> GetList(int UserId)
        {
            IList<WishList> objectList = new List<WishList>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_WishList_List", objectList, new object[] { UserId });

            return objectList;
        }

        #endregion

        #region Insert

        public static long Insert(int UserId, string ListName, string Explanation, string FirstName, string LastName, string Email, string Phone, string Address_Name, string Address_Phone,
                                  short Address_City, short Address_County, string Address, string ListUrl, bool DeliveryByReceive, string DeliveryDate, string ListPass,
                                  bool Published, bool Voucher, bool Delegate, string Delegate_FirstName, string Delegate_LastName, string Delegate_Phone, string Delegate_Email,
                                  int CreateUser)
        {
            long Id = (long)SqlHelper.ExecuteScalar(dbParameters.dsnStore, "SPR_ESTORE_WishList_Insert", new object[] { UserId, ListName, Explanation, FirstName, LastName, Email,
                                                    Phone, Address_Name, Address_Phone, Address_City, Address_County, Address, ListUrl, DeliveryByReceive, DeliveryDate, ListPass,
                                                    Published, Voucher, Delegate, Delegate_FirstName, Delegate_LastName, Delegate_Phone, Delegate_Email, CreateUser });
            return Id;
        }

        #endregion

        #region Publish

        public static void Publish(int UserId, long ListId, string Publish, int Count, int UpdateUser)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_WishList_Publish", new object[] { UserId, ListId, Publish, Count, UpdateUser });
        }

        #endregion

        #region Update

        public static void Update(int UserId, long ListId, string ListName, string Explanation, string FirstName, string LastName, string Email, string Phone, string Address_Name,
                                  string Address_Phone, short Address_City, short Address_County, string Address, string ListUrl, bool DeliveryByReceive, string DeliveryDate,
                                  string ListPass, bool Published, bool Voucher, bool Delegate, string Delegate_FirstName, string Delegate_LastName, string Delegate_Phone,
                                  string Delegate_Email, int UpdateUser)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_WishList_Update", new object[] { UserId, ListId, ListName, Explanation, FirstName, LastName, Email,
                                      Phone, Address_Name, Address_Phone, Address_City, Address_County, Address, ListUrl, DeliveryByReceive, DeliveryDate, ListPass,
                                      Published, Voucher, Delegate, Delegate_FirstName, Delegate_LastName, Delegate_Phone, Delegate_Email, UpdateUser });
        }

        #endregion

        #region Delete

        public static void Delete(int UserId, long ListId)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_WishList_Delete", new object[] { UserId, ListId });
        }

        #endregion

        #region ProductWishList

        public static IList<ProductWishList> ProductWishList(int UserId, int ProductId)
        {
            IList<ProductWishList> objectList = new List<ProductWishList>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_WishList_Product", objectList, new object[] { UserId, ProductId });

            return objectList;
        }

        #endregion

        #region GetRelatedUsers

        public static IList<RelatedUser> GetRelatedUsers(int UserId)
        {
            var cacheKey = "GetRelatedUsers" + UserId;
            if (HttpRuntime.Cache[cacheKey] != null)
            {
                return HttpRuntime.Cache[cacheKey] as IList<RelatedUser>;
            }


            IList<RelatedUser> objectList = new List<RelatedUser>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_User_Related_Users", objectList, new object[] { UserId });
            HttpRuntime.Cache.Add(cacheKey, objectList, null, DateTime.UtcNow.AddDays(1), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
            return objectList;
        }

        #endregion

        #region GetUserRelatedLists

        public static IList<UserRelatedList> GetUserRelatedLists(int UserId)
        {
            IList<UserRelatedList> objectList = new List<UserRelatedList>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_User_Related_Lists", objectList, new object[] { UserId });

            return objectList;
        }

        #endregion
    }
}
